package com.shawn.example.mvvmdemo.ui

import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.WindowCompat
import androidx.lifecycle.Observer
import androidx.lifecycle.lifecycleScope
import com.alibaba.android.arouter.launcher.ARouter
import com.gyf.immersionbar.ImmersionBar
import com.jetpack.mvvm.lib.base.BaseActivity
import com.jetpack.mvvm.lib.base.RouterConstant
import com.jetpack.mvvm.lib.base.bus.LiveDataBus
import com.jetpack.mvvm.lib.base.constants.Constants
import com.jetpack.mvvm.lib.binding.ext.viewBind
import com.orhanobut.logger.Logger
import com.shawn.example.mvvmdemo.databinding.ActivitySplashBinding
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

class SplashActivity : AppCompatActivity() {
    companion object {
        private const val TAG = "SplashActivity"
    }

    private val bind: ActivitySplashBinding by viewBind()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        Log.e(TAG, "onCreate")
        configScreen()
        setContentView(bind.root)
        observerData()
    }

    private fun configScreen() {
        ImmersionBar.with(this)
            .transparentBar()
            .statusBarDarkFont(true)
            .navigationBarDarkIcon(true)
            .init()
    }

    private fun observerData() {
        val livedata = LiveDataBus.get().with(Constants.LiveBusKeys.THIRD_SDK_INIT)
        if (livedata.value != null) {
            goToMainPage()
        }else livedata.observe(this) {
            goToMainPage()
        }
    }

    private fun goToMainPage() {
        ARouter.getInstance().build(RouterConstant.App.PAGE_MAIN)
            .withString("nodeId", "12345678")
            .navigation()
        finish()
    }
}